package org.xx.armory.swing.builders;

import java.util.ArrayList;
import java.util.List;

public class SplitPaneModelBuilder
        extends ComponentModelBuilder<SplitPaneModel>
        implements ContainerModelBuilder {
    private int axis;
    private int dividerLocation;
    private List<ComponentModel> children;

    public SplitPaneModelBuilder() {
        this.children = new ArrayList<>(2);
    }

    public SplitPaneModelBuilder setAxis(
            int axis
    ) {
        this.axis = axis;
        return this;
    }

    public SplitPaneModelBuilder setDividerLocation(
            int dividerLocation
    ) {
        this.dividerLocation = dividerLocation;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public SplitPaneModelBuilder addChild(
            ComponentModel child
    ) {
        this.children.add(child);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public SplitPaneModel build() {
        final ComponentModel first = this.children.size() > 0 ? this.children.get(0) : null;
        final ComponentModel last = this.children.size() > 1 ? this.children.get(1) : null;
        return new SplitPaneModel(getLineInfo(), getName(), isVisible(), axis, this.dividerLocation, first, last);
    }
}
